<html><head><title>HoneyViz Homepage</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
include "validate.php";
include "header.php";
?>
<h2>Status Page</h2>
<?php
$query = "	SELECT database_name AS NAME 
		FROM new_submissions;";

$result = mysql_query($query);

echo "<table><tr><td>";

while ($row = mysql_fetch_array($result))
{
	$table_name = $row['NAME'];
	echo $table_name . "</td><td>";
	$query = "	SELECT has_started AS start, has_finished AS fin
			FROM honeyviz_" . $table_name . ".submissions_state
			LIMIT 1;";

	$tmpResult = mysql_query($query);
	
	$tmp = mysql_fetch_array($tmpResult);

	if ($tmp['start'] == 0)
	{
		echo "<img src = 'red.jpg' alt = 'Error!'/>";
	}
	else if ($tmp['fin'] == 0)
	{
		echo "<img src = 'yellow.jpg' alt = 'Updating!'/>";
	}
	else
	{
		echo "<img src = 'green.jpg' alt = 'Finished!'/>";
	}
	echo "</td></tr><tr><td>";
}

$query = "	SELECT is_updating AS is_update
		FROM update_state 
		LIMIT 1;";

$result = mysql_query($query);

$row = mysql_fetch_array($result);

echo "Database Status</td><td>";

if ($row['is_update'] == 0)
{
	echo "<img src = 'green.jpg' alt = 'Finished!'/>";
}
else
{
	echo "<img src = 'red.jpg' alt = 'Updating!'/>";
}

echo "</td></tr></table>";
?>
</body></html>